/**
 * @author Justin Akin
 * @version Action Pals Core Library 0.1.0
 */
package com.actionpals.display
{	
	import flash.geom.Rectangle;
	import com.actionpals.base.BaseClass;
	
	/**
	 * 
	 */
	internal class Scale9Info extends BaseClass
	{
			
	//--------------------------------------------------------------------------------
	//	Protected Member Variables
	//--------------------------------------------------------------------------------
		
		protected var _sourceRect:Rectangle;
		protected var _scaleRect:Rectangle;
		
	//--------------------------------------------------------------------------------
	//	Constructor
	//--------------------------------------------------------------------------------
	
		/**
		 * Constructor
		 */
		 public function Scale9Info( sourceRect:Rectangle, scaleRect:Rectangle )
		 {
		 	super();	
		 	init( sourceRect, scaleRect );	
		 }
			
	//--------------------------------------------------------------------------------
	//	Public Methods
	//--------------------------------------------------------------------------------
		 
		/**
		 *
		 */ 
		public function resize( w:Number, h:Number ):void
		{	
			var dW:Number = w - _sourceRect.width;
			var dH:Number = h - _sourceRect.height;
		 	
		 	_sourceRect.width = w;
		 	_sourceRect.height = h;
		 	_scaleRect.width += dW;
		 	_scaleRect.height += dH;
		 }
			
	//--------------------------------------------------------------------------------
	//	Getters and Setters
	//--------------------------------------------------------------------------------
	
		public function get topLeftRect():Rectangle
		{	
			var dX:Number = _sourceRect.x;
			var dY:Number = _sourceRect.y;
			var dW:Number = _scaleRect.x - _sourceRect.x;
			var dH:Number = _scaleRect.y - _sourceRect.y;
			
			return new Rectangle( dX, dY, dW, dH );
		}
	
		public function get topMiddleRect():Rectangle
		{				
			var dX:Number = _scaleRect.x;
			var dY:Number = _sourceRect.y;
			var dW:Number = _scaleRect.width;
			var dH:Number = _scaleRect.y - _sourceRect.y;
			
			return new Rectangle( dX, dY, dW, dH );		
		}
	
		public function get topRightRect():Rectangle
		{	
			var dX:Number = _scaleRect.right;
			var dY:Number = _sourceRect.y;
			var dW:Number = _sourceRect.right - _scaleRect.right;
			var dH:Number = _scaleRect.y - _sourceRect.y;
			
			return new Rectangle( dX, dY, dW, dH );				
		}
	
		public function get centerLeftRect():Rectangle
		{	
			var dX:Number = _sourceRect.x;
			var dY:Number = _scaleRect.y;
			var dW:Number = _scaleRect.x - _sourceRect.x;
			var dH:Number = _scaleRect.height;
			
			return new Rectangle( dX, dY, dW, dH );						
		}
	
		public function get centerMiddleRect():Rectangle
		{							
			return _scaleRect;				
		}
	
		public function get centerRightRect():Rectangle
		{	
			var dX:Number = _scaleRect.right;
			var dY:Number = _scaleRect.y;
			var dW:Number = _sourceRect.right - _scaleRect.right;
			var dH:Number = _scaleRect.height;
			
			return new Rectangle( dX, dY, dW, dH );
		}
	
		public function get bottomLeftRect():Rectangle
		{	
			var dX:Number = _sourceRect.x;
			var dY:Number = _scaleRect.bottom;
			var dW:Number = _scaleRect.x - _sourceRect.x;
			var dH:Number = _sourceRect.bottom - _scaleRect.bottom;
			
			return new Rectangle( dX, dY, dW, dH );
		}
	
		public function get bottomMiddleRect():Rectangle
		{				
			var dX:Number = _scaleRect.x;
			var dY:Number = _scaleRect.bottom;
			var dW:Number = _scaleRect.width;
			var dH:Number = _sourceRect.bottom - _scaleRect.bottom;
			
			return new Rectangle( dX, dY, dW, dH );				
		}
	
		public function get bottomRightRect():Rectangle
		{	
			var dX:Number = _scaleRect.right;
			var dY:Number = _scaleRect.bottom;
			var dW:Number = _sourceRect.right - _scaleRect.right;
			var dH:Number = _sourceRect.bottom - _scaleRect.bottom;
			
			return new Rectangle( dX, dY, dW, dH );	
		}
			
	//--------------------------------------------------------------------------------
	//	Protected Methods
	//--------------------------------------------------------------------------------
		 
		/**
		 *
		 */ 
		 protected function init( sourceRect:Rectangle, scaleRect:Rectangle ):void
		 {	
		 	_sourceRect = sourceRect;
		 	_scaleRect = scaleRect;
		 	
		 	if( _scaleRect.x < _sourceRect.x ) throw new Error( "The postion of the scaleRect must be within the perimeter of the sourceRect" );
		 	if( _scaleRect.y < _sourceRect.y ) throw new Error( "The postion of the scaleRect must be within the perimeter of the sourceRect" );
		 	if( _scaleRect.width > _sourceRect.width ) throw new Error( "The width of the scaleRect must be less than or equal to the width of the sourceRect" );
		 	if( _scaleRect.height > _sourceRect.height ) throw new Error( "The height of the scaleRect must be less than or equal to the height of the sourceRect" );	 	
		 }	
	}	
}